//
//  UIButton+Util.swift
//  1604_LimitFree
//
//  Created by 千锋 on 16/9/26.
//  Copyright © 2016年 Mabin. All rights reserved.
//

import UIKit


extension UIButton
{
    class func createBtn(frame : CGRect, title : String?, bgImageName : String?,target : AnyObject?, action : Selector) -> UIButton {

        let button = UIButton(type: .Custom)
        button.frame = frame
        if let tmpTitle = title
        {
            button.setTitle(tmpTitle, forState: UIControlState.Normal)
            button.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        }
        
        if let imageName = bgImageName
        {
            button.setBackgroundImage(UIImage(named: imageName), forState: UIControlState.Normal)
        }
        if target != nil && action != nil
        {
            button.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        }
        
        return button
    }
}
